﻿namespace Jhong.FunMVCBlog.Core.Data
{
    using Jhong.Data.Core.Common;
    using Jhong.Data.MYSQL;

    public abstract class BaseData
    {
        //protected DBContext _dbContext = new MYSQLContext(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);

        private DBContext __dbContext;

        protected DBContext _dbContext
        {
            get
            {
                if (null == this.__dbContext) this.__dbContext = new MYSQLContext("Server=127.0.0.1;Database=funmvcblog;Uid=root;Pwd=root;Port=3306;CharSet=utf8;");
                return this.__dbContext;
            }
        }

        protected LogData _logData { get { return new LogData(); } }

        public virtual bool Insert<T>(T model)
        {
            using (this._dbContext)
            {
                return this._dbContext.InsertEntity<T>(model) > 0;
            }
        }

        public virtual bool Update<T>(T model)
        {
            using (this._dbContext)
            {
                return this._dbContext.UpdateEntity(model) > 0;
            }
        }

        public virtual bool Delete<T>(T model)
        {
            using (this._dbContext)
            {
                return this._dbContext.DeleteEntity(model) > 0;
            }
        }
    }
}